(function(){
    $('.header').lavalamp({
		easing: 'easeOutBack',
        setOnClick:true
	});
    
    $("#qualitySecondMenu li").click(function(){
        $("#qualitySecondMenu li").removeClass('checkActive');
        $(this).addClass('checkActive');
    });
    /*$('#myTabs a').click(function (e) {
        e.preventDefault();
        $(this).tab('show')
    });
*/
    //getAllData({});

    //获取所有的查询条件
    getSearchCondition();
    //获取所有的站点
    common.getallstation({},function (data) {
        var str = {list:data};
        var decreasestationCode = template("decreasestationCodemodal",str);
        document.getElementById("decreasestationCode").innerHTML = decreasestationCode;
        //$('#decreasestationCode').comboSelect();
    });
    //获取检查人名单
    common.getcheckperson({},function (data) {
        var str = {list:data};
        var checkperson = template("checkpersonmodal",str);
        document.getElementById("rummager").innerHTML = checkperson;
    });

    //获取时间段和月份
    var year = new Date().getFullYear();
    var line = year-2000;
    var str = "<option>请选择</option>";
    for (var i = 0;i<line;i++){
        str +="<option>"+(year-i)+"</option>"
    }
    $("#startyear").html(str);
    $("#startyear").change(function () {
        var startmonth ="<option>请选择</option>";
        for (var m =1;m<=12;m++){
        	if(m<10){
        		m = "0"+m;
        		startmonth += "<option>"+(m)+"</option>"
           	}
        	if(m>=10){
        		startmonth += "<option>"+(m)+"</option>"
        	}
        }
        $("#startmonth").html(startmonth);
    });
    
    $("#endyear").html(str);
    $("#endyear").change(function () {
        var endmonth ="<option>请选择</option>";
        for (var m =1;m<=12;m++){
        	if(m<10){
        		m = "0"+m;
        		endmonth += "<option>"+(m)+"</option>"
           	}
        	if(m>=10){
        		endmonth += "<option>"+(m)+"</option>"
        	}
        }
        $("#endmonth").html(endmonth);
    });
}());

//======================================================================================================================
//获取四级联动数据
var areadata = [];
function getSearchCondition() {
    common.rununit({},function (data) {
      	
        var str = {list:data};
        var getrununitinfo = template("getrununitinfo",str);
        document.getElementById("unit").innerHTML = getrununitinfo;
        areadata=data;
    })
    
    common.stationtype({},function(data){
    	console.log(data)
    	var str = {list:data};
        var getrununitinfo = template("getstationtypeinfo",str);
        document.getElementById("category").innerHTML = getrununitinfo;
        areadata=data;
    })
   
}

var unit = $("#unit"),category=$("#category"),area=$("#area"),stationchose=$("#stationchose"),talkType=$("#talkType");
			//运行单位           //站点类型															//评估类型

//运行单位
unit.change(function () {	
	var obj=document.getElementsByName('unit');
	var RunUnit=''; 
	for(var i=0; i<obj.length; i++){ 
		if(obj[i].checked) RunUnit+="runUnitIds="+obj[i].value+'&'; //如果选中，将value添加到变量s中
	} 
	var rununit = RunUnit.substring(0,RunUnit.length - 1);
	sessionStorage.setItem("rununit",rununit);
	var params = sessionStorage.getItem("rununit") +'&'+ sessionStorage.getItem("stationtype");
	console.log(params);
	getCityList(params);
});

//站点类型
category.change(function(){
	var obj=document.getElementsByName('stationtype');
	var StationType=''; 
	for(var i=0; i<obj.length; i++){ 
		if(obj[i].checked) StationType+="stationTypeIds="+obj[i].value+'&'; //如果选中，将value添加到变量s中
	} 
	
	var stationtype = StationType.substring(0,StationType.length - 1);
	sessionStorage.setItem("stationtype",stationtype);
	var params = sessionStorage.getItem("rununit") +'&'+ sessionStorage.getItem("stationtype");
	console.log(params);
	getCityList(params);
})

//评估类型
talkType.change(function(){
	var obj=document.getElementsByName('choose');
	var talkType='';
	for(var i=0; i<obj.length; i++){ 
		if(obj[i].checked) talkType+="status="+obj[i].value+'&'; //如果选中，将value添加到变量s中
	} 
	var talktype = talkType.substring(0,talkType.length - 1);
	sessionStorage.setItem("talktype",talktype);
	console.log(talktype);
})
	
//查询城市列表
function getCityList(params){
	common.citylist(params,function(data){
        
        var str = {list:data};
        var citylist = template("chooseCity",str);
        document.getElementById("citylist").innerHTML = citylist;
       $(".cityName").click(function(){
       		//阻止input的点击事件
			$(".citylist").click(function(){
			  event.stopPropagation();
			})
			$(".regionlist").click(function(){
			  event.stopPropagation();
			})
			
			if($(this).find("ul").css("display") == "block"){
				$(this).find("ul").css("display","none")
			}else if($(this).find("ul").css("display") == "none"){
				$(this).find("ul").css("display","block")
			}
		})
       
		$(".citylist").on("change",function(){
	        if($(this).is(':checked')){
	          $(this).nextAll("ul").find(".regionlist").prop('checked', true);
	        }else{
	          $(this).nextAll("ul").find(".regionlist").removeAttr("checked");
	        }
      	})
    });
}

//点击按钮
function searchs(){
	var startyear = $("#startyear").val();
    var startmonth = $("#startmonth").val();
    var endyear = $("#endyear").val();
    var endmonth = $("#endmonth").val();
    var start = "start"+'='+ startyear +'-'+ startmonth +'-'+ "01";
    var end = "end"+'='+ endyear +'-'+ endmonth +'-'+ "01";
    var time = start +'&'+ end;
    console.log(time);
    
    var city = "";
//  评估类型为1或3传站点,评估类型为2传城市,站点
	if(sessionStorage.getItem("talktype") == "status=1" || sessionStorage.getItem("talktype") == "status=3"){
		for(var i = 0;i < $(".regionlist").length;i++){
          if($($(".regionlist")[i]).is(':checked')){
            city +="stationCodes="+$(".regionlist")[i].value+'&';
          }
        }
	}
	if(sessionStorage.getItem("talktype") == "status=2"){
		for(var i = 0;i < $(".citylist").length;i++){
          if($($(".citylist")[i]).is(':checked')){
            city +="cityIds="+$(".citylist")[i].value+'&';
          }
        }
		for(var i = 0;i < $(".regionlist").length;i++){
          if($($(".regionlist")[i]).is(':checked')){
            city +="stationCodes="+$(".regionlist")[i].value+'&';
          }
        }
	}

    var citys = city.substring(0,city.length - 1);

	var params = sessionStorage.getItem("rununit") +'&'+ sessionStorage.getItem("stationtype")+'&'+ sessionStorage.getItem("talktype")+'&'+ time+'&'+citys;
	sessionStorage.setItem("params",params);
	console.log(params)
//	1传输率
	common.transmission(params,function(data){
        var talktype=sessionStorage.getItem("talktype");
		var str = {list:data};
        if(talktype.indexOf("3")>0){
            var chuanshuContent = template('chuanshutables', str);
            document.getElementById('chuanshulv').innerHTML = chuanshuContent;
        }else{
            var chuanshulv = template('chuanshutable',str);
            document.getElementById('chuanshulv').innerHTML = chuanshulv;
        }
        
	})
//	1有效天数
	common.workday(params,function(data){
        var talktype=sessionStorage.getItem("talktype");
		var str = {list:data};
        if(talktype.indexOf("3")>0){
            var workscoretable = template('workscore', str);
            document.getElementById('defenpingjiabiao').innerHTML = workscoretable;
        }else{
            var workday = template('validtable', str);
            document.getElementById('defenpingjiabiao').innerHTML = workday;
        }
        
	})
//	1运行质量得分
	common.qualityscore(params,function(data){
        var talktype=sessionStorage.getItem("talktype");
		var str = {list:data};
        if(talktype.indexOf("3")>0){
            var testcalscorce = template('testcalscorce', str);
		    document.getElementById('jiancekaohejieguo').innerHTML = testcalscorce;
        }else{
            var qualityscore = template('calscorce',str);
		    document.getElementById('jiancekaohejieguo').innerHTML = qualityscore;
        }
		
	})
//	1运行单位运行质量
	common.runquality(params,function(data){
        var talktype=sessionStorage.getItem("talktype");
		var str = {list:data};
        if(talktype.indexOf("3")>0){
            var runquality = template('runtable', str);
		    document.getElementById('zhiliangpinggubiao').innerHTML = runquality;
        }else{
            var runquality = template('runquality',str);
		    document.getElementById('zhiliangpinggubiao').innerHTML = runquality;
        }
		
	})

//	运行质量体系
	common.qualityunit(params,function(data){
		var str = {list:data};
		var runqualitytixi = template('runqualitytixi',str);
		document.getElementById('yunxingzhiliangtixitable').innerHTML = runqualitytixi;
	})
	//	日常评价表
	common.daytest(params,function(data){
        var talktype=sessionStorage.getItem("talktype");
		var str = {list:data};
        if(talktype.indexOf("3")>0){
            var runquality = template('dailytest', str);
            console.log(runquality)
            console.log(str)
		    document.getElementById('richanggongzuopingjiabiao').innerHTML = runquality;
        }else{
            var daytest = template('yunxingdaily',str);
		    document.getElementById('richanggongzuopingjiabiao').innerHTML = daytest;
        }
		
	})
	common.losepoint(params,function(data){
		var talktype=sessionStorage.getItem("talktype");
        var str = {list:data};
        if(talktype.indexOf("3")>0){
            var daytest = template('monthdeduct',str);
		    document.getElementById('jianchakoufenbiao').innerHTML = daytest;
        }else{
            var daytest = template('losepoint',str);
		    document.getElementById('jianchakoufenbiao').innerHTML = daytest;
        }
		
	})
}

//      传输率模态框赋值
function layShow(index){
	console.log(index)
	var params = sessionStorage.getItem("params");
	console.log(params);
	common.transmission(params,function(data){
		
		var strs = {list:data[index].dataResult};
        var chuanshuContent = template('chuanshutables', strs);
        document.getElementById('chuanshuContent').innerHTML = chuanshuContent;
	})
}

//有效天数模态框
function layShows(index){
	var params = sessionStorage.getItem("params");
	common.workday(params,function(data){
		
		var strs = {list:data[index].dataResult};
        var workscoretable = template('workscore', strs);
        document.getElementById('scorecontent').innerHTML = workscoretable;
	})
}

//考核结果模态框
function testcalscorce(index){
	var params = sessionStorage.getItem("params");
	common.qualityscore(params,function(data){
		var strs = {list:data[index].dataResult};
        var testcalscorce = template('testcalscorce', strs);
        document.getElementById('testcalscorces').innerHTML = testcalscorce;
	})
}

//运行单位质量评估表模态框
function runquality(index){
	var params = sessionStorage.getItem("params");
	common.runquality(params,function(data){
		
		var strs = {list:data[index].dataResult};
        var runquality = template('runtable', strs);
        document.getElementById('runqualis').innerHTML = runquality;
	})
}

//质量体系模态框
function qualityunit(index){
	var params = sessionStorage.getItem("params");
	common.qualityunit(params,function(data){
		
		var strs = {list:data[index].dataResultMap.dataResult};
		console.log(strs);
        var runquality = template('unitquality', strs);
        document.getElementById('myModalunits').innerHTML = runquality;
	})
}

//日常评估模态框
function daliy(index){
	var params = sessionStorage.getItem("params");
	common.daytest(params,function(data){

		var strs = {list:data[index].dataResult};
		
        var runquality = template('dailytest', strs);
        document.getElementById('daliytable').innerHTML = runquality;
	})
}
//扣分详情
function losepointDetail(index){
    var params = sessionStorage.getItem("params");
    common.losepoint(params,function(data){
		
        var str = {list:data[index].dataResult,date:data[index].checkTime};
		var daytest = template('monthdeduct',str);
		document.getElementById('losepointDetail').innerHTML = daytest;
	})
}


























//============================================================================================================================

//根据条件搜索
function getsearchParams() {
    var unit = $("#unit").val(),
        startyear = $("#startyear").val(),
        startmonth = $("#startmonth").val(),
        endyear = $("#endyear").val(),
        endmonth = $("#endmonth").val(),
        area = $("#area").val(),
        category = $("#category").val(),
        stationchose = $("#stationchose").val(),
        params = {};
    if (startmonth!="请选择"){
        if(startyear=="请选择"){
            alert("您还没有选择年份");
            return false
        }
    }
    if(startyear!="请选择"){
        if(startmonth=="请选择"){
            alert("您还没有选择月份");
            return false
        }
    }
    if (startmonth!="请选择"&&startyear!="请选择"){
        params.month = startyear+"-"+startmonth
    }
    if (area!=""){
        params.cityId = area
    }
    if (category==""){
        category = ""
    }else {
        params.stationTypeId = category
    }
    if (stationchose!=""){
        params.stationCode = stationchose
    }
    if (unit!=""){
        params.runUnitId = unit;
        if(startyear=="请选择"||startmonth=="请选择"){
            alert("时间不能为空");
            return false
        }
    }
    return params;
}
function detailLay(index){
	console.log(index)
	console.log(dataResult)
}
//查询条件
function search(){
    if(!getsearchParams()){
        return
    }
    var params = getsearchParams();
    getData.conditons(params)
}


//获取六个表格的数据
function getAllData(params){
	//质控检查扣分表
    common.monthdeduct(params,function(data){
        var month = "";
        if (data.length>0){
            month = parseInt(data[0].checkTime.split('-')[1]);
        }
        var str = {title:month,list:data};
        var monthdeduct = template('monthdeduct',str);
        //document.getElementById('jianchakoufenbiao').innerHTML = monthdeduct;
    });
    //传输率
    common.monthtransfer(params,function(data){
    	console.log(params);
    	console.log(data)
        var month = "";
        if (data.length>0){
            month =  parseInt(data[0].monthTime.split('-')[1]);
        }
        var str = {title:month,list:data};
        var chuanshulv = template('chuanshutable', str);
        document.getElementById('chuanshulv').innerHTML = chuanshulv;
    });
    //有效天数得分评价表
    common.monthvalidate(params,function(data){
        var month = "";
        if (data.length>0){
            month =  parseInt(data[0].monthTime.split('-')[1]);
        }
        var str = {title:month,list:data};
        var hvalidate = template('validtable', str);
        document.getElementById('defenpingjiabiao').innerHTML = hvalidate;
    });
     //考核结果
    common.calscorce(params,function(data){
        var month = "";
         if (data.length>0){
             month = month = parseInt(data[0].monthTime.split('-')[1]);
         }
        var str = {title:month,list:data};
        var calscorce = template('calscorce',str);
        document.getElementById('jiancekaohejieguo').innerHTML = calscorce;
    })
    //运行单位运行质量评估表
    common.monthunitworking(params,function(data){
        var month = "";
        if (data.monthTime){
            month = parseInt(data.monthTime.split('-')[1]);
        }
        var str = {title:month,list:data};
        var monthunitworking = template('monthunitworking',str);
        document.getElementById('zhiliangpinggubiao').innerHTML = monthunitworking;
    });
    //运行单位日常工作月评价表
    common.daytest(params,function(data){
       
        var str = {list:data};
        var monthRunUnitQC = template('yunxingdaily',str);
        document.getElementById('richanggongzuopingjiabiao').innerHTML = monthRunUnitQC;
    });
   

}





//查询条件选择
var unit = $("#unit"),category=$("#category"),area=$("#area"),stationchose=$("#stationchose");
//var text1="<option value=''>请选择站点类型</option>",text2 = "<option value=''>选择所在区域</option>",text3= "<option value=''>选择站点名称</option>";
//unit.change(function () {
//  category.html(text1);
//  area.html(text2);
//  stationchose.html(text3);
//  var index = $("#unit option:selected")[0].className;
//  var seconddata = areadata[index].stationTypeMsg;
//  var str = {list:seconddata};
//  var getstationtypeinfo = template("getstationtypeinfo",str);
//  document.getElementById("category").innerHTML = getstationtypeinfo
//});
//category.change(function () {
//  area.html(text2);
//  stationchose.html(text3);
//  var index = $("#unit option:selected")[0].className;
//  var index1 = $("#category option:selected")[0].className;
//  var thirddata = areadata[index].stationTypeMsg[index1].cityMsg;
//  var str = {list:thirddata};
//  var getcityinfo = template("getcityinfo",str);
//  document.getElementById("area").innerHTML = getcityinfo
//});
//area.change(function () {
//  stationchose.html(text3);
//  var index = $("#unit option:selected")[0].className;
//  var index1 = $("#category option:selected")[0].className;
//  var index2 = $("#area option:selected")[0].className;
//  var fourthdata = areadata[index].stationTypeMsg[index1].cityMsg[index2].stationMsg;
//  var str = {list:fourthdata};
//  var stationchosecode = template("stationchosecode",str);
//  document.getElementById("stationchose").innerHTML = stationchosecode;
//});

var getData = {
    conditons:function (params) {
        //传输率
        common.monthtransferConditions(params,function (data) {
            var month = "";
            if (data.length>0){
                month =  parseInt(data[0].monthTime.split('-')[1]);
            }
            var str = {title:month,list:data};
            var chuanshulv = template('chuanshutable', str);
            document.getElementById('chuanshulv').innerHTML = chuanshulv;
        });
        //有效天数
        common.monthvalidateConditions(params,function (data) {
            var month = "";
            if (data.length>0){
                month = parseInt(data[0].monthTime.split('-')[1]);
            }
            var str = {title:month,list:data};
            var hvalidate = template('validtable', str);
            document.getElementById('defenpingjiabiao').innerHTML = hvalidate;
        });
        //日常工作
        common.monthrununitworkingConditions(params,function (data) {
            var month = "";
            if (data.monthTime){
                month = parseInt(data.monthTime.split('-')[1]);
            }
            var str = {title:month,list:data};
            var monthunitworking = template('monthunitworking',str);
            document.getElementById('zhiliangpinggubiao').innerHTML = monthunitworking;
        });
        //扣分表
        common.monthdeductConditions(params,function (data) {
            var month = "";
            if (data.length>0){
                month = parseInt(data[0].checkTime.split('-')[1]);
            }
            var str = {title:month,list:data};
            var monthdeduct = template('monthdeduct',str);
            document.getElementById('jianchakoufenbiao').innerHTML = monthdeduct;
        });
        //质量评估
        common.monthRunUnitQCConditions(params,function (data) {
            var month = "";
            if (data.length>0){
                month = parseInt(data[0].checkTime.split('-')[1]);
            }
            var str = {title:month,list:data};
            var monthRunUnitQC = template('monthRunUnitQC',str);
            document.getElementById('richanggongzuopingjiabiao').innerHTML = monthRunUnitQC;
        });
        //查询得分
        common.calscorceConditions(params,function (data) {
            var month = "";
            if (data.length>0){
                month = parseInt((data[0].monthTime.split(' ')[0]).split('-')[1]);
            }
            var str = {title:month,list:data};
            var calscorce = template('calscorce',str);
            document.getElementById('jiancekaohejieguo').innerHTML = calscorce;
        })
    }
};



var scoreobj = {
    "score1":0,
    "score2":0,
    "score3":0,
    "score4":0,
    "score5":0,
    "score6":0,
    "score7":0,
    "score8":0,
    "score9":0,
    "score10":0,
    "score11":0,
    "score12":0,
    "score13":0,
    "score14":0,
    "score15":0,
    "score16":0,
    "score17":0,
    "score18":0,
    "score19":0,
    "score20":0,
    "score21":0,
    "score22":0,
    "score23":0,
    "score24":0,
    "score25":0,
    "score26":0,
    "score27":0,
    "mark1":"",
    "mark2":"",
    "mark3":"",
    "mark4":"",
    "mark5":"",
    "mark6":"",
    "mark7":"",
    "mark8":"",
    "mark9":"",
    "mark10":"",
    "mark11":"",
    "mark12":"",
    "mark13":"",
    "mark14":"",
    "mark15":"",
    "mark16":"",
    "mark17":"",
    "mark18":"",
    "mark19":"",
    "mark20":"",
    "mark21":"",
    "mark22":"",
    "mark23":"",
    "mark24":"",
    "mark25":"",
    "mark26":"",
    "mark27":"",
    "detail1":"",
    "detail2":"",
    "detail3":"",
    "detail4":"",
    "detail5":"",
    "detail6":"",
    "detail7":"",
    "detail8":"",
    "detail9":"",
    "detail10":"",
    "detail11":"",
    "detail12":"",
    "detail13":"",
    "detail14":"",
    "detail15":"",
    "detail16":"",
    "detail17":"",
    "detail18":"",
    "detail19":"",
    "detail20":"",
    "detail21":"",
    "detail22":"",
    "detail23":"",
    "detail24":"",
    "detail25":"",
    "detail26":"",
    "detail27":"",
    "detail28":"",
    "detail29":"",
    "detail30":"",
    "detail31":"",
    "detail32":"",
    "detail33":"",
    "detail34":"",
    "detail35":"",
    "detail36":"",
    "detail37":"",
    "detail38":"",
    "detail39":"",
    "detail40":"",
    "detail41":"",
    "detail42":"",
    "detail43":"",
    "detail44":""
};
function getdatascore(id,score,obj) {
    if (id.indexOf("score")>=0){
        var reg = /^[1-9]\d*$/;
        var scorevalue = parseInt(($(obj).val()).trim());
        var number = parseInt(score);
        if (reg.test(scorevalue)&&scorevalue<=number){
            scoreobj[id] = $(obj).val();
        }else {
            $(obj).val("0");
            scoreobj[id] = 0;
            alert("只能填写符合规则的数字，且分数不能大于"+number)
        }
    }else {
        scoreobj[id] = $(obj).val();
    }
}
function getDetailData(id,type,obj,bool,num){
     var volume = $(obj).val().trim();
     var reg = /^[1-9]\d*$/;
     if(reg.test(volume)&&volume!=""){
         if(bool){
             scoreobj[id] = volume;
             var isNext = parseInt(num);
             var main = parseInt(type);
             var first = main+2;
             var second = main+1;
             var prev = main-1;
             if(num=="1"){
                 var secondValue = ($("#detail"+second).val()).trim();
                 var currentValue = ($(obj).val()).trim();
                 if (secondValue!=""&&currentValue!=""){
                     var avg = Math.abs((((currentValue-secondValue)/secondValue)*100).toFixed(2));
                     $("#detail"+first).html(avg);
                 }
                 scoreobj["detail"+second]=secondValue;
                 scoreobj["detail"+type]=currentValue;
                 scoreobj["detail"+first]=avg;
             }else {
                 var prevValue = ($("#detail"+prev).val()).trim();
                 var currentValue = ($(obj).val()).trim();
                 if (secondValue!=""&&currentValue!=""){
                     var avg = Math.abs((((prevValue-currentValue)/currentValue)*100).toFixed(2));
                     $("#detail"+second).html(avg);
                 }
                 scoreobj["detail"+prev]=prevValue;
                 scoreobj["detail"+type]=currentValue;
                 scoreobj["detail"+second]=avg;
             }
         }else {
             scoreobj["detail"+type]=$(obj).val();
         }
     }else {
         alert("您所输入的格式不正确");
         $(obj).val('')
     }

}


//新增扣分表数据
function adddecreaseGrade() {
    var dataparams = getsearchParams();
    for (var i=1;i<28;i++){
        var mark = "mark"+i;
        var score = "score"+i;
        if (scoreobj[mark]==''){
            scoreobj[mark] = $("#"+mark).val()
        }
       if (scoreobj[score]==''){
            if($("#"+score).val()!=''){
                scoreobj[score] = $("#"+score).val()
            }else {
                scoreobj[score] = 0
            }
       }
    }
    for (var j=1;j<45;j++){
        var detail = "detail"+j;
        var newdata = $("#"+detail).val().trim()||$("#"+detail).html().trim();
        if (scoreobj[detail]==''&&newdata==''){
            alert('质量控制效果数据不能为空，请填写完整');
            return
        }else if(scoreobj[detail]==''){
            scoreobj[detail] = newdata
        }
    }
    var stationCode = $("#decreasestationCode").val();
    var dateinfo = $("#dateinfo").val();
    var rummager = $("#rummager").val();
    var updatestationcode = $("#updateCode").val();
    if(updatestationcode!="0"){
        stationCode = updatestationcode;
    }
    if (!dateinfo){
        alert("请先选择时间");
        return
    }
    var day = parseInt(((dateinfo.split(' ')[0]).split('-'))[1]);
    var year = parseInt(((dateinfo.split(' ')[0]).split('-'))[0]);
    var tomonth = (new Date().getMonth()+1);
    var toyear = (new Date().getFullYear());
    if(stationCode==0){
        alert("您还没有选择站点");
        return
    }
    if (year!=toyear){
        alert("你只能选择当前年份");
        return
    }
    if (day!=tomonth){
        alert("你只能选择当前月份");
        return
    }
    scoreobj["stationCode"] = stationCode;
    scoreobj["checkTime"] = dateinfo;
    scoreobj["checkPerson"] = rummager;
    common.savedeductscore(scoreobj,function (data) {
        if(data.result){
            //质控检查扣分表
            console.log(dataparams);
            common.monthdeductConditions(dataparams,function(data){
                var month = "";
                if (data.length>0){
                    month = parseInt(data[0].checkTime.split('-')[1]);
                }
                var str = {title:month,list:data};
                var monthdeduct = template('monthdeduct',str);
                document.getElementById('jianchakoufenbiao').innerHTML = monthdeduct;
            });
            alert("提交成功");
            $(".btn-default").click();
        }
    })

}

$('#myModal').on('show.bs.modal', function (e) {
    /*获取扣分表信息*/
    var invoker = $(e.relatedTarget);
    var id = "";
    if (invoker[0].childNodes[1]){
        var title = invoker[0].title;
        id = invoker[0].childNodes[1].innerHTML;
        var text = title.split('-')[1];
        var areatitle= title.split('-')[0];
        if(text=="详情"){
            $("#myModalLabel").html("扣分详情表");
            $("#checkperson").hide();
            $(".modal-footer").hide();
            $("#totalscoretr").show();
        }else {
            $("#myModalLabel").html("扣分修改");
            $("#checkperson").show();
            $(".modal-footer").show();
            $("#totalscoretr").hide();
        }
        var params = {detailId:id};
        $("#stationInfo").html(areatitle);
        $("#updateCode").val(id);
        $("#checkestation .combo-select ").hide();
        common.findByDetail(params,function (data) {
            var personname = data.checkPerson;
            var person = $("#rummager option");
            for (var i=0;i<person.length;i++){
               if($(person[i]).val()==personname){
                   $(person[i]).attr('selected',true)
               }
            }
            for (var i =0;i<data.deductList.length;i++){
                var num = parseInt(i)+1;
                $("#score"+num).val(data.deductList[i].score);
                $("#mark"+num).val(data.deductList[i].detailMark);
                $("#totalscore").html(data.totalDeduct);
                if(text=="详情"){
                    $("#score"+num).attr("disabled","disabled");
                    $("#mark"+num).attr("disabled","disabled");
                }else {
                    $("#score"+num).removeAttr("disabled");
                    $("#mark"+num).removeAttr("disabled");
                }
            }
            for (var j =0;j<data.detailMap.length;j++){
               for (var key  in data.detailMap[j]){
                   var obj = {};
                   obj[key] = data.detailMap[j][key];
                   $("#"+key).val(data.detailMap[j][key]);
                   $("#"+key).html(data.detailMap[j][key]);
                   if(text=="详情"){
                       $("#"+key).attr("disabled","disabled")
                   }else {
                       $("#"+key).removeAttr("disabled");
                   }
               }
            }
        })
    }else {
        $("#myModalLabel").html("扣分新增表");
        for (var i=1;i<45;i++){
            $("#detail"+i).removeAttr("disabled");
            $("#detail"+i).val('');
            $("#detail"+i).html('');
        }
        for(var j=1;j<28;j++){
            $("#score"+j).removeAttr("disabled");
            $("#score"+j).val("");
            $("#mark"+j).removeAttr("disabled");
            $("#mark"+j).val("");
        }
        $("#checkestation").show();
        $("#checkperson").show();
        $(".modal-footer").show();
        $("#totalscoretr").hide();
        $("#stationInfo").html('');
        $("#updateCode").val('0');
        $("#checkestation .combo-select ").show();
    }

});
function deletescoreTable(id){
    var params = {"detailId":id};
    common.deletedeductscore(params,function (data) {
        if(data.result=="true"){
            alert("删除成功");
            //质控检查扣分表
            var dataparams = getsearchParams();
            common.monthdeductConditions(dataparams,function(data){
                var month = "";
                if (data.length>0){
                    month = parseInt(data[0].checkTime.split('-')[1]);
                }
                var str = {title:month,list:data};
                var monthdeduct = template('monthdeduct',str);
                document.getElementById('jianchakoufenbiao').innerHTML = monthdeduct;
            });
        }
    })
}
